import 'package:dio/dio.dart';

class QwsConnectionTimingInterceptor extends Interceptor{

  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    final startTime = DateTime.now().millisecondsSinceEpoch;
    options.extra['startTime'] = startTime;
    handler.next(options);
  }

  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
    final endTime = DateTime.now().millisecondsSinceEpoch;
    final startTime = response.requestOptions.extra['startTime'] as int;
    final connectionDuration = endTime - startTime;
    print('连接耗时: $connectionDuration 毫秒');
    handler.next(response);
  }
}